FROM ubuntu:18.04



# build参数
ARG user=ht
ARG password=docker
ARG homedir=/home/${user}

# 元数据
LABEL maintainer="jiejie" 
LABEL email="jiejietop@gmail.com"
LABEL org.label-schema.schema-version="1.2.0"
LABEL org.label-schema.build-date="2023-03"
LABEL org.label-schema.name="jiejie:ubuntu18.04"
LABEL org.label-schema.description="jiejie:ubuntu18.04"
LABEL org.label-schema.docker.cmd="\
docker run -it --rm --privileged \
    --net=host \
    --ipc=host \
    --pid=host \
    -e DISPLAY=$DISPLAY \
    -v ~/Documents:/home/ht/workspace \
    -v ~/eon:/home/ht/eon \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -v /run/dbus/system_bus_socket:/run/dbus/system_bus_socket:ro \
    -d jiejie:ubuntu18.04 \
"

USER root

# tuna.tsinghua.edu.cn
# aliyun.com
RUN  sed -i s@/ports.ubuntu.com/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list \
    && sed -i s@/security.ubuntu.com/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list


RUN apt-get update

RUN apt-get install -y apt-utils software-properties-common locales sudo

RUN locale-gen zh_CN.UTF-8
ENV \
    LANG=zh_CN.UTF-8 \
    DEBIAN_FRONTEND=noninteractive \
    TERM=xterm


# 添加用户：赋予sudo权限，指定密码
RUN useradd --create-home --no-log-init --shell /bin/bash ${user} \
    && adduser ${user} sudo \
    && echo "${user}:${password}" | chpasswd

# 指定容器起来的工作目录
WORKDIR ${homedir}

# =============安装基础依赖================
RUN apt-get remove -y --purge xserver-xorg

RUN apt-get install --no-install-recommends -y \
    gnupg2 \
    mesa-utils \
    sudo \
    tmux \
    wget \
    curl \
    apt-file \
    xserver-xorg

RUN apt-get install -y \
    zsh \
    git \
    tig \
    g++ \
    cmake \
    dbus \
    tree \
    nmap \
    openssl \
    tmux \
    vim \
    libyaml-cpp-dev \
    net-tools \
    htop \
    stress \
    gdb \
    libprotobuf-dev \
    protobuf-compiler \
    libgraphviz-dev \
    qtbase5-dev \
    libqt5qml5 \
    libqt5quick5 \
    libqt5quickwidgets5 \
    qml-module-qtquick2 \
    libqt5svg5-dev
    

# ########################## 安全环境管理 ################################
RUN curl -s https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# ##########################  安装 eCAL ################################
# RUN sh -c '. /etc/lsb-release && echo "deb http://ppa.launchpad.net/ecal/ecal-latest/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ecal-latest.list'

RUN add-apt-repository ppa:ecal/ecal-latest -y
RUN apt-get update -y
RUN apt-get install ecal -y

# Set network_enabled = true in ecal.ini.
# You can omit this, if you only need local communication.
RUN awk -F"=" '/^network_enabled/{$2="= true"}1' /etc/ecal/ecal.ini > /etc/ecal/ecal.tmp && \
	rm /etc/ecal/ecal.ini && \
	mv /etc/ecal/ecal.tmp /etc/ecal/ecal.ini 

# Print the eCAL config
RUN ecal_config


# ########################## zsh环境配置 ################################
RUN chsh -s /bin/zsh
RUN usermod -s /bin/zsh ${user}

RUN git clone https://gitee.com/jiejieTop/ohmyzsh.git ${homedir}/.oh-my-zsh
RUN git clone https://gitee.com/jiejieTop/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-${homedir}/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
RUN git clone https://gitee.com/jiejieTop/zsh-autosuggestions.git ${ZSH_CUSTOM:-${homedir}/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
RUN git clone https://gitee.com/jiejieTop/git-open.git ${ZSH_CUSTOM:-${homedir}/.oh-my-zsh/custom}/plugins/git-open
RUN cp ${homedir}/.oh-my-zsh/templates/zshrc.zsh-template ${homedir}/.zshrc
RUN sed -i 's/plugins=(git)/plugins=(z git sudo extract vi-mode git-open safe-paste command-not-found colored-man-pages zsh-syntax-highlighting vscode zsh-autosuggestions)/g' ${homedir}/.zshrc \
    && sed -i 's/# DISABLE_AUTO_UPDATE="true"/DISABLE_AUTO_UPDATE="true"/g' ${homedir}/.zshrc \
    && sed -i 's/# DISABLE_AUTO_TITLE="true"/DISABLE_AUTO_TITLE="true"/g' ${homedir}/.zshrc

# ########################## tmux环境配置 ################################
RUN echo 'set-option -g mouse on' > ${homedir}/.tmux.conf
RUN echo 'set -g pane-border-status top' >> ${homedir}/.tmux.conf
RUN echo 'set-option -g allow-rename off' >> ${homedir}/.tmux.conf
RUN echo 'set -g pane-border-format "#{pane_index} #T #{pane_current_command}"' >> ${homedir}/.tmux.conf
RUN echo 'bind-key -T prefix R send-keys "renamePane" C-m' >> ${homedir}/.tmux.conf
RUN echo '' >> ${homedir}/.tmux.conf

USER ${user}
